<?php

namespace DC\UserCenter\Models;

use App\Models\BaseModel;

class UserWalletModel extends BaseModel
{
    protected $table = 'users_wallet';

    protected $primaryKey = 'member_id';

    public $dateFormat = 'U';

    protected $guarded = [];

    public function user()
    {
        return $this->belongsTo('DC\UserCenter\Models\UserBaseModel','member_id','member_id');
    }

    public function compareSurplus(float $money,$user_id,$field='money1')
    {
        $surplus = self::where('member_id',$user_id)->value($field);
        if(!$surplus){
            return false;
        }

        if($surplus-abs($money)>=0){
            return true;
        }

        return false;
    }

    public function pay(float $money,$user_id,$field)
    {

    }
}
